local skill = fk.CreateSkill{
  name = "tea__yuanbo",
}
local getCanBeDiscardedCards = function(player)
  local arr = {}
  for _, id in ipairs(player:getCardIds("he")) do
    if not player:prohibitDiscard(id) then
      table.insert(arr, id)
    end
  end
  return arr
end
---@type TrigSkelSpec<AimFunc>
local yuanbo = {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and data.from ~= player.id and data.card then
      if data.card.trueName == "slash" and player:inMyAttackRange(target) then
        return #getCanBeDiscardedCards(player) > 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cids = room:askToDiscard(target, {
      min_num = 1,
      max_num = 2,
      skill_name = skill.name,
      include_equip = true,
      cancelable = false,
      pattern = ".",
      prompt = "#tea__yuanbo-choose",
      skip = true,
    })
    if #cids > 0 then
      room:throwCard(cids, skill.name, target, target)
      if not target.dead then
        target:drawCards(#cids, skill.name)
      end
      if table.find(cids, function(id)
        local c = Fk:getCardById(id)
        return c.type == Card.TypeEquip
      end) then
        data.use.nullifiedTargets = data.use.nullifiedTargets or {}
        table.insertIfNeed(data.use.nullifiedTargets, target)
        if data.from then
          local from = data.from
          local card = Fk:cloneCard("duel")
          if not from.dead and from:canUseTo(card, player) then
            local use = {
              from = data.from,
              tos = { player },
              card = card,
              extraUse = true,
            }
            room:useCard(use)
          end
        end
      end
    end
  end,
}
skill:addEffect(fk.TargetConfirmed, yuanbo)
return skill